package com.dajie.pt.entity.base;

import java.util.Date;

import com.dajie.pt.utils.DateTimeUtils;


public class BaseEntity implements java.io.Serializable
{

	private static final long serialVersionUID = 456363658915138837L;
	
	protected Integer id;

	protected static final String DATE_FORMAT = "yyyy-MM-dd";

	protected static final String TIME_FORMAT = "HH:mm:ss";

	protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

	protected static final String TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.S";

	public String date2String(final java.util.Date date, final String dateFormat)
	{
		return DateTimeUtils.format(date, dateFormat);
	}

	public <T extends java.util.Date> T string2Date(final String dateString, final String dateFormat,
			final Class<T> targetResultType)
	{
		return DateTimeUtils.parse(dateString, dateFormat, targetResultType);
	}

	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}
	
	public Date castToDate(Object dateo)
	{
		Date date = null;
		if(dateo != null)
		{
			if(dateo instanceof Date)
			{
				date = (Date)dateo;
			}else if(dateo instanceof Long)
			{
				date = new Date((Long)dateo);
			}else
			{
				date = new Date((Long)dateo);
			}
		}
		return date;
	}
}
